@c Emacs integration

@node Emacs integration
@section Emacs integration

Emacs is the canonical development environment for Scheme48.  The
@file{scheme.el} and @file{cmuscheme.el} packages provide support for
editing Scheme code and running inferior Scheme processes,
respectively.  Also, the @file{scheme48.el} package provides more
support for integrating directly with
Scheme48.@footnote{@file{scheme48.el} is based on the older
@file{cmuscheme48.el}, which is bundled with Scheme48 in the
@file{emacs/} directory.  Since @file{cmuscheme48.el} is older and less
developed, it is not documented here.}  @file{scheme.el} and
@file{cmuscheme.el} come with GNU Emacs; @file{scheme48.el} is
available separately from

@display
@uref{http://www.emacswiki.org/cgi-bin/wiki/download/scheme48.el}.@end display

To load @file{scheme48.el} if it is in the directory @var{emacs-dir},
add these lines to your @file{.emacs}:

@lisp
(add-to-list 'load-path "@var{emacs-dir}/")
(autoload 'scheme48-mode "scheme48"
  "Major mode for improved Scheme48 integration."
  t)
(add-hook 'hack-local-variables-hook
          (lambda ()
            (if (and (boundp 'scheme48-package)
                     scheme48-package)
                (progn (scheme48-mode)
                       (hack-local-variables-prop-line)))))@end lisp

The @code{add-hook} call sets Emacs up so that any file with a
@code{scheme48-package} local variable specified in the file's
@code{-*-} line or @code{Local Variables} section will be entered in
Scheme48 mode.  Files should use the @code{scheme48-package} variable
to enable Scheme48 mode; they should not specify Scheme48 mode
explicitly, since this would fail in Emacs instances without
@file{scheme48.el}.  That is, put this at the tops of files:

@lisp
;;; -*- Mode: Scheme; scheme48-package: ... -*-@end lisp

@noindent
Avoid this at the tops of files:

@lisp
;;; -*- Mode: Scheme48 -*- @end lisp

There is also SLIME48, the Superior Lisp Interaction Mode for Emacs
with Scheme48.  It provides a considerably higher level of integration
the other Emacs packages do, although it is less mature.  It is at

@display
@uref{http://mumble.net/~campbell/scheme/slime48.tar.gz};@end display

@noindent
there is also a Darcs repository@footnote{Darcs is a revision control
system; see

@display
@uref{http://www.darcs.net/}@end display

@noindent
for more details.} at

@display
@uref{http://mumble.net/~campbell/darcs/slime48/}.@end display

Finally, @file{paredit.el} implements pseudo-structural editing
facilities for S-expressions: it automatically balances parentheses and
provides a number of high-level operations on S-expressions.
@file{Paredit.el} is available on the web at

@display
@uref{http://mumble.net/~campbell/emacs/paredit.el}.@end display

@file{cmuscheme.el} defines these:

@deffn {Emacs command} run-scheme [scheme-prog]
Starts an inferior Scheme process or switches to a running one.  With
no argument, this uses the value of @code{scheme-program-name} to run
the inferior Scheme system; with a prefix argument @var{scheme-prog},
this invokes @var{scheme-prog}.
@end deffn

@defvr {Emacs variable} scheme-program-name
The Scheme program to invoke for inferior Scheme processes.
@end defvr

Under @code{scheme48-mode} with @file{scheme.el}, @file{cmuscheme.el},
and @file{scheme48.el}, these keys are defined:

@table @asis
@item @kbd{C-M-f} --- @code{forward-sexp}
@itemx @kbd{C-M-b} --- @code{backward-sexp}
@itemx @kbd{C-M-k} --- @code{kill-sexp}
@itemx @kbd{@key{ESC} C-@key{DEL}} (@emph{not} @kbd{C-M-@key{DEL}}) --- @code{backward-kill-sexp}
@itemx @kbd{C-M-q} --- @code{indent-sexp}
@itemx @kbd{C-M-@@} --- @code{mark-sexp}
@itemx @kbd{C-M-@key{SPC}} --- @code{mark-sexp}
S-expression manipulation commands.  @kbd{C-M-f} moves forward by one
S-expression; @kbd{C-M-b} moves backward by one.  @kbd{C-M-k} kills the
S-expression following the point; @kbd{@key{ESC} C-@key{DEL}} kills the
S-expression preceding the point.  @kbd{C-M-q} indents the S-expression
following the point.  @kbd{C-M-@@} & @kbd{C-M-@key{SPC}}, equivalent to
one another, mark the S-expression following the point.

@item @kbd{C-c z} --- @code{switch-to-scheme}
Switches to the inferior Scheme process buffer.

@item @kbd{C-c C-l} --- @code{scheme48-load-file}
Loads the file corresponding with the current buffer into Scheme48.  If
that file was not previously loaded into Scheme48 with @kbd{C-c C-l},
Scheme48 records the current interaction environment in place as it
loads the file; if the file was previously recorded, it is loaded into
the recorded environment.  @xref{Emacs integration commands}.

@item @kbd{C-c C-r} --- @code{scheme48-send-region}
@itemx @kbd{C-c M-r} --- @code{scheme48-send-region-and-go}
@kbd{C-c C-r} sends the currently selected region to the current
inferior Scheme process.  The file of the current buffer is recorded as
in the @kbd{C-c C-l} command, and code is evaluated in the recorded
package.  @kbd{C-c M-r} does similarly, but subsequently also switches
to the inferior Scheme process buffer.

@item @kbd{C-M-x} --- @code{scheme48-send-definition}
@itemx @kbd{C-c C-e} --- @code{scheme48-send-definition}
@itemx @kbd{C-c M-e} --- @code{scheme48-send-definition-and-go}
@kbd{C-M-x} (GNU convention) and @kbd{C-c C-e} send the top-level
definition that the current point is within to the current inferior
Scheme process.  @kbd{C-c M-e} does similarly, but subsequently also
switches to the inferior Scheme process buffer.  @kbd{C-c C-e} and
@kbd{C-c M-e} also respect Scheme48's file/environment mapping.

@item @kbd{C-x C-e} --- @code{scheme48-send-last-sexp}
Sends the S-expression preceding the point to the inferior Scheme
process.  This also respects Scheme48's file/environment mapping.
@end table
